﻿@model ProductsByTagModel

@using Nop.Core
@using Nop.Core.Domain.Catalog
@using Nop.Core.Domain.Seo

@inject IWebHelper webHelper
@inject SeoSettings seoSettings

@{
    Layout = "_ColumnsTwo";

    //title
    NopHtml.AddTitleParts(!string.IsNullOrEmpty(Model.MetaTitle) ? Model.MetaTitle : T("PageTitle.ProductsByTag", Model.TagName).Text);
    //meta
    NopHtml.AddMetaDescriptionParts(Model.MetaDescription);
    NopHtml.AddMetaKeywordParts(Model.MetaKeywords);

    //page class
    NopHtml.AppendPageCssClassParts("html-product-tag-page");

    //canonical URL
    if (seoSettings.CanonicalUrlsEnabled)
    {
        var productsByTagUrl = (await NopUrl.RouteGenericUrlAsync<ProductTag>(new { SeName = Model.TagSeName }, webHelper.GetCurrentRequestProtocol())).ToLowerInvariant();
        NopHtml.AddCanonicalUrlParts(productsByTagUrl, seoSettings.QueryStringInCanonicalUrlsEnabled);
    }
}

@section CatalogFilters {
    @await Html.PartialAsync("_CatalogFilters", Model.CatalogProductsModel)
}

<div class="page product-tag-page">
    <div class="page-title">
        <h1>@string.Format(T("Products.Tags.ProductsTaggedWith").Text, Model.TagName)</h1>
    </div>
    <div class="page-body">
        @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.ProductsByTagTop, additionalData = Model })
        @await Html.PartialAsync("_CatalogSelectors", Model.CatalogProductsModel)
        @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.ProductsByTagBeforeProductList, additionalData = Model })
        @{
            var catalogProductsViewData = new ViewDataDictionary(ViewData);
            catalogProductsViewData["fetchUrl"] = Html.Raw(Url.RouteUrl(NopRouteNames.Ajax.GET_TAG_PRODUCTS, new { tagId = Model.Id }));
        }
        @await Html.PartialAsync("_CatalogProducts", Model.CatalogProductsModel, catalogProductsViewData)
        @await Component.InvokeAsync(typeof(WidgetViewComponent), new { widgetZone = PublicWidgetZones.ProductsByTagBottom, additionalData = Model })
    </div>
</div>